package ca.cbc.util;

import java.security.*;
import java.math.*;
import java.io.*;

public class Digest {

	private String hash;

	public Digest(String input) {
		this.hash = input;
	}

	public Digest() {
		this.hash = null;
	}

	public String getHash() {

		String input = this.hash;

		try {
			MessageDigest m = MessageDigest.getInstance("MD5");
			m.update(input.getBytes(),0,input.length());
			hash = new BigInteger(1,m.digest()).toString(16);
		} catch (NoSuchAlgorithmException nsae) {
			return "Algorithm not found";
		} 

		return hash;
	}

	public String getHash(String input) {
		this.hash = input;
		return getHash();
	}

}
